package com.chengh.vhr.controller.system.basic;

import com.chengh.vhr.model.Position;
import com.chengh.vhr.model.RespBean;
import com.chengh.vhr.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 职位管理相关的controller
 */
@RequestMapping("/system/basic/pos")
@RestController
public class PositionController {

    @Autowired
    PositionService positionService;

    /**
     * 获得所有的职位信息
     * @return
     */
    @GetMapping("/getAllPosition")
    public List<Position> getAllPosition() {
        return positionService.getAllPosition();
    }

    /**
     * 添加职位
     * @param position
     * @return
     */
    @PostMapping("/addPosition")
    public RespBean addPosition(@RequestBody Position position) {
        if(positionService.addPosition(position) == 1){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }

    /**
     * 更新职位信息
     * @param position
     * @return
     */
    @PutMapping("/updatePosition")
    public RespBean updatePosition(@RequestBody Position position) {
        if(positionService.updatePosition(position) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    /**
     * 删除职位信息
     * @param id
     * @return
     */
    @DeleteMapping("/deletePositionById/{id}")
    public RespBean deletePositionById(@PathVariable Integer id) {
        if(positionService.deletePositionById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    /**
     * 批量删除职位信息
     * @param ids
     * @return
     */
    @DeleteMapping("/deletePositionByIds")
    public RespBean deletePositionByIds(@RequestBody List<Integer> ids) {
        if(positionService.deletePositionByIds(ids) == ids.size()) {
            return RespBean.ok("批量删除成功!");
        }
        return RespBean.error("批量删除失败!");
    }
}
